package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {


    /**
     * Kafka修改文章配置
     *
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
//        获取文章id
        Long articleId = (Long) map.get("articleId");
//        获取文章enable,0下架，1上架
        Object enable = map.get("enable");
        boolean isDown = true;
        if (enable.equals(1)) {
            isDown = false;
        }
        //修改文章配置
        QueryWrapper<ApArticleConfig> wrapper = new QueryWrapper<>();
        wrapper.eq("article_id", articleId);
        ApArticleConfig apArticleConfig = baseMapper.selectOne(wrapper);
        apArticleConfig.setIsDown(isDown);
        baseMapper.updateById(apArticleConfig);
    }
}